import { _decorator, Component, Input, input, KeyCode, Node, sys } from 'cc';
import ComponentBase from './engine/ComponentBase';
import { Base64Helper } from './engine/Base64Helper';
import { Logger } from './engine/Logger';
import QRCodeHelper from './engine/QRCodeHelper';
import { WebUtil } from './engine/WebUtil';
import UIManager from './engine/UIManager';
import { EventManager } from './engine/EventManager';
import { EngineConfig } from './engine/EngineConfig';
import DateUtil from './engine/DateUtil';
import ServerTimer from './engine/ServerTimer';
import GameController from './GameController';
import { UIHelper } from './game/util/UIHelper';
import { GameSocket } from './engine/GameSocket';
import { ProtoManager } from './lib/net/protobuf/ProtoManager';
import { ViewConfig } from './game/config/ViewConfig';
const { ccclass, property } = _decorator;

@ccclass('Main')
export class Main extends ComponentBase {

    public static instance: Main;

    start() {
        Main.instance = this;
        WebUtil.init()
        UIManager.instance.init(this.getChild(this.node, "uiRoot"))
        input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
        GameController.instance.init();
        ProtoManager.instance.init()
        UIManager.instance.showView(ViewConfig.viewConfig.ViewLoading)
        // UIHelper.showTip("abcdtewtetewhkljasdoifjodijfd")
    }

    private onKeyDown(event) {
        // UIHelper.showTip("keyCode:" + event.keyCode)
        // 下:1004
        //上:1003
        //左:1000
        //右:1001
        //确定:1005
        //返回：6
        //菜单:18
        if (event.keyCode == KeyCode.F1) {

        }
    }

    update(deltaTime: number) {
        EventManager.instance.dispatch(EngineConfig.Event_Type.Event_FrameUpdate, ServerTimer.now);
    }
}

